package com.rdk.service.impl;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.rdk.entity.CheckRequstParam;
import com.rdk.entity.CheckResponseEntity;
import com.rdk.service.CheckUserService;
import com.rdk.wechat.common.Constant;
import com.rdk.wechat.request.impl.BaseRequest;
import com.rdk.wechat.util.JSONutils;

/**
 * @ClassName: CheckUserServiceImpl
 * @Description: TODO(用户凭证的获取)
 * @author dinghao
 * @date 2016年1月7日 上午11:48:33
 * 
 */
public class CheckUserServiceImpl extends BaseRequest implements CheckUserService {

	public CheckUserServiceImpl() {
		super(null);
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.rdk.service.CheckUserService#getUserAccount(com.rdk.entity.UserParma)
	 */
	public CheckResponseEntity getUserAccount(CheckRequstParam userParma) {
		String jsonParma = JSONutils.ObjectToJson(userParma);
		System.out.println("request.json==" + jsonParma);
		we.setWebFlag("publicSentimentUrl");
		we.setServiceName(Constant.PublicSentimentServiceName.CHECK);
		we.setOpName(Constant.PublicSentimentOpName.USERAGENT);
		String url = this.getUrl(we);
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost = new HttpPost(url);
		httppost.addHeader("usergid", "PaMhX9fZD4m+oAV+LSmSQN7H1zq+uqzq");
		StringEntity myEntity = new StringEntity(jsonParma, ContentType.APPLICATION_JSON);// 设置具体请求用用类型
																							// 用
																							// json。
		httppost.setEntity(myEntity);// 设置请求体
		String jsonStr = null;
		try {
			HttpResponse response = httpclient.execute(httppost);
			int stateCode = response.getStatusLine().getStatusCode();
			if (stateCode == 200) {
				HttpEntity entity = response.getEntity();
				if (entity != null) {
					jsonStr = EntityUtils.toString(entity, "UTF-8");
					System.out.println("------------" + jsonStr);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();

		}
		return JSONutils.jsonToBean(jsonStr, CheckResponseEntity.class);
	}
}
